﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAlgorithm.二叉树
{
    public class BinaryDemo
    {
        /// <summary>
        /// 二叉树的前序遍历
        /// </summary>
        /// <param name="root"></param>
        public static void PreOrderTraversal(TreeNode? root)
        {
            if(root==null) return;
            Console.WriteLine(root.Value);
            PreOrderTraversal(root.Left);
            PreOrderTraversal(root.Right);
        }
        /// <summary>
        /// 中序遍历
        /// </summary>
        /// <param name="root"></param>
        public static void InOrderTraVeral(TreeNode? root)
        {
            if(root==null) return ;
            InOrderTraVeral(root.Left);
            Console.WriteLine(root.Value);
            InOrderTraVeral(root.Right);

        }
        /// <summary>
        /// 后序遍历
        /// </summary>
        /// <param name="root"></param>
        public static void PostOrderTraVeral(TreeNode? root)
        {
            if(root==null) return ;
            PostOrderTraVeral(root.Left);
            PostOrderTraVeral(root.Right);
            Console.WriteLine(root.Value);
        }
    }
}
